﻿using Sidvall.Collections;
using System.Linq;

namespace Sidvall.AuthorizationManager.Model.DataPortalManagers
{
    [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Maintainability", "CA1506:AvoidExcessiveClassCoupling")]
    public partial class AuthorizationScopeResourceActionManager<TEntity, TList> : Sidvall.Business.BusinessManagerBase
        where TEntity : global::Sidvall.AuthorizationManager.Data.IAuthorizationScopeResourceAction
        where TList : Sidvall.Data.IDataRowProvider<global::Sidvall.AuthorizationManager.Data.IAuthorizationScopeResourceAction>
    {
        #region Public Members

        #region DeleteItemByPrimaryKeyAsync

        public async System.Threading.Tasks.Task<int> DeleteItemByPrimaryKeyAsync(long authorizationScopeResourceActionId)
        {
            return await DeleteItemByPrimaryKeyAsync(authorizationScopeResourceActionId, null, null, null).ConfigureAwait(false);
        }
        public async System.Threading.Tasks.Task<int> DeleteItemByPrimaryKeyAsync(long authorizationScopeResourceActionId, global::Sidvall.Data.DeleteCriteria<global::Sidvall.AuthorizationManager.Data.Fields.AuthorizationScopeResourceActionField> criteria, string strategyContext, global::Sidvall.Data.ObjectParameterCollection objectParameters)
        {
            if (criteria == null)
                criteria = Sidvall.Data.CriteriaManager.NewDeleteCriteria<global::Sidvall.AuthorizationManager.Data.Fields.AuthorizationScopeResourceActionField>();
            if (criteria.Filter == null)
                criteria.Filter = new global::Sidvall.Data.Filter<global::Sidvall.AuthorizationManager.Data.Fields.AuthorizationScopeResourceActionField>();
            criteria.Filter.AddFilterItem(global::Sidvall.AuthorizationManager.Data.Fields.AuthorizationScopeResourceActionField.AuthorizationScopeResourceActionId, Sidvall.Data.ComparisonOperator.Equal, authorizationScopeResourceActionId);

            return await DeleteItemsAsync(criteria, strategyContext, objectParameters).ConfigureAwait(false);
        }

        #endregion
        #region DeleteItemsByPrimaryKeysAsync

        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")]
        public async System.Threading.Tasks.Task<int> DeleteItemsByPrimaryKeysAsync(System.Collections.Generic.IEnumerable<long> keys)
        {
            return await DeleteItemsByPrimaryKeysAsync(keys, null, null, null).ConfigureAwait(false);
        }
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")]
        public async System.Threading.Tasks.Task<int> DeleteItemsByPrimaryKeysAsync(System.Collections.Generic.IEnumerable<long> keys, global::Sidvall.Data.DeleteCriteria<global::Sidvall.AuthorizationManager.Data.Fields.AuthorizationScopeResourceActionField> criteria, string strategyContext, global::Sidvall.Data.ObjectParameterCollection objectParameters)
        {
            if ((keys == null) || (!keys.Any()))
                return 0;
            if (criteria == null)
                criteria = Sidvall.Data.CriteriaManager.NewDeleteCriteria<global::Sidvall.AuthorizationManager.Data.Fields.AuthorizationScopeResourceActionField>();
            if (criteria.Filter == null)
                criteria.Filter = new global::Sidvall.Data.Filter<global::Sidvall.AuthorizationManager.Data.Fields.AuthorizationScopeResourceActionField>();
            criteria.Filter.AddFilterItem(global::Sidvall.AuthorizationManager.Data.Fields.AuthorizationScopeResourceActionField.AuthorizationScopeResourceActionId, Sidvall.Data.ComparisonOperator.Equal, keys);

            return await DeleteItemsAsync(criteria, strategyContext, objectParameters).ConfigureAwait(false);
        }

        #endregion
        #region DeleteItemsByAuthorizationScopeAsync

        public async System.Threading.Tasks.Task<int> DeleteItemsByAuthorizationScopeAsync(long authorizationScopeId)
        {
            return await DeleteItemsByAuthorizationScopeAsync(authorizationScopeId, null, null, null).ConfigureAwait(false);
        }
        public async System.Threading.Tasks.Task<int> DeleteItemsByAuthorizationScopeAsync(long authorizationScopeId, global::Sidvall.Data.DeleteCriteria<global::Sidvall.AuthorizationManager.Data.Fields.AuthorizationScopeResourceActionField> criteria, string strategyContext, global::Sidvall.Data.ObjectParameterCollection objectParameters)
        {
            if (criteria == null)
                criteria = Sidvall.Data.CriteriaManager.NewDeleteCriteria<global::Sidvall.AuthorizationManager.Data.Fields.AuthorizationScopeResourceActionField>();
            if (criteria.Filter == null)
                criteria.Filter = new global::Sidvall.Data.Filter<global::Sidvall.AuthorizationManager.Data.Fields.AuthorizationScopeResourceActionField>();
            criteria.Filter.AddFilterItem(global::Sidvall.AuthorizationManager.Data.Fields.AuthorizationScopeResourceActionField.AuthorizationScopeId, Sidvall.Data.ComparisonOperator.Equal, authorizationScopeId);

            return await DeleteItemsAsync(criteria, strategyContext, objectParameters).ConfigureAwait(false);
        }
        public async System.Threading.Tasks.Task<int> DeleteItemsByAuthorizationScopeAsync(System.Collections.Generic.IEnumerable<long> authorizationScopeIds)
        {
            return await DeleteItemsByAuthorizationScopeAsync(authorizationScopeIds, null, null, null).ConfigureAwait(false);
        }
        public async System.Threading.Tasks.Task<int> DeleteItemsByAuthorizationScopeAsync(System.Collections.Generic.IEnumerable<long> authorizationScopeIds, global::Sidvall.Data.DeleteCriteria<global::Sidvall.AuthorizationManager.Data.Fields.AuthorizationScopeResourceActionField> criteria, string strategyContext, global::Sidvall.Data.ObjectParameterCollection objectParameters)
        {
            if (criteria == null)
                criteria = Sidvall.Data.CriteriaManager.NewDeleteCriteria<global::Sidvall.AuthorizationManager.Data.Fields.AuthorizationScopeResourceActionField>();
            if (criteria.Filter == null)
                criteria.Filter = new global::Sidvall.Data.Filter<global::Sidvall.AuthorizationManager.Data.Fields.AuthorizationScopeResourceActionField>();
            criteria.Filter.AddFilterItem(global::Sidvall.AuthorizationManager.Data.Fields.AuthorizationScopeResourceActionField.AuthorizationScopeId, Sidvall.Data.ComparisonOperator.Equal, authorizationScopeIds);

            return await DeleteItemsAsync(criteria, strategyContext, objectParameters).ConfigureAwait(false);
        }

        #endregion
        #region DeleteItemsAsync

        public async System.Threading.Tasks.Task<int> DeleteItemsAsync()
        {
            global::Sidvall.Data.DeleteCriteria<global::Sidvall.AuthorizationManager.Data.Fields.AuthorizationScopeResourceActionField> criteria;

            criteria = Sidvall.Data.CriteriaManager.NewDeleteCriteria<global::Sidvall.AuthorizationManager.Data.Fields.AuthorizationScopeResourceActionField>();

            return await DeleteItemsAsync(criteria, null, null).ConfigureAwait(false);
        }
        public async System.Threading.Tasks.Task<int> DeleteItemsAsync(global::Sidvall.Data.DeleteCriteria<global::Sidvall.AuthorizationManager.Data.Fields.AuthorizationScopeResourceActionField> criteria)
        {
            return await DeleteItemsAsync(criteria, null, null).ConfigureAwait(false);
        }
        public async System.Threading.Tasks.Task<int> DeleteItemsAsync(global::Sidvall.Data.DeleteCriteria<global::Sidvall.AuthorizationManager.Data.Fields.AuthorizationScopeResourceActionField> criteria, string strategyContext, global::Sidvall.Data.ObjectParameterCollection objectParameters)
        {
            if (criteria == null)
                throw new System.ArgumentNullException(nameof(criteria));
            var dataPortalContext = Sidvall.Business.DataPortalManager.NewContext(global::Sidvall.AuthorizationManager.Data.Model.DomainObjects.AuthorizationScopeResourceAction, Sidvall.Security.Operations.DeleteItems, strategyContext, criteria, 0);
            dataPortalContext.ObjectParameters.Merge(objectParameters);
            return await DeleteItemsAsync(dataPortalContext).ConfigureAwait(false);
        }
        partial void OnBeforeDelete(Sidvall.Business.DataPortalContext<int, global::Sidvall.Data.DeleteCriteria<global::Sidvall.AuthorizationManager.Data.Fields.AuthorizationScopeResourceActionField>> dataPortalContext);
        partial void OnAfterDelete(Sidvall.Business.DataPortalContext<int, global::Sidvall.Data.DeleteCriteria<global::Sidvall.AuthorizationManager.Data.Fields.AuthorizationScopeResourceActionField>> dataPortalContext);
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")]
        public async System.Threading.Tasks.Task<int> DeleteItemsAsync(Sidvall.Business.DataPortalContext<int, global::Sidvall.Data.DeleteCriteria<global::Sidvall.AuthorizationManager.Data.Fields.AuthorizationScopeResourceActionField>> dataPortalContext)
        {
            if (dataPortalContext == null)
                throw new System.ArgumentNullException(nameof(dataPortalContext));
            do
            {
                try
                {
                    global::Sidvall.AuthorizationManager.Model.DataPortalEventManager.DataPortalInvoke(dataPortalContext);
                    OnBeforeDelete(dataPortalContext);
                    await dataPortalContext.DoTaskAsync().ConfigureAwait(false);
                    if (dataPortalContext.Result == Sidvall.Business.DataPortalResult.None)
                    {
                        await GetDataPortal(dataPortalContext).DeleteItemsAsync(dataPortalContext).ConfigureAwait(false);
                    }
                    OnAfterDelete(dataPortalContext);
                    global::Sidvall.AuthorizationManager.Model.DataPortalEventManager.DataPortalInvokeComplete(dataPortalContext);
                    await dataPortalContext.DoTaskAsync().ConfigureAwait(false);
                }
                catch (System.Exception ex)
                {
                    dataPortalContext.Exception = Sidvall.Business.DataPortalManager.GetDataPortalException(ex, dataPortalContext);
                    global::Sidvall.AuthorizationManager.Model.DataPortalEventManager.DataPortalException(dataPortalContext);
                    await dataPortalContext.DoTaskAsync(!dataPortalContext.Retry).ConfigureAwait(false);
                }
            } while (dataPortalContext.DoRetry());
            return dataPortalContext.ResultValueItem;
        }

        #endregion
        #region GetItemByPrimaryKeyAsync

        public async System.Threading.Tasks.Task<TEntity> GetItemByPrimaryKeyAsync(long authorizationScopeResourceActionId)
        {
            return await GetItemByPrimaryKeyAsync(authorizationScopeResourceActionId, null, null, null).ConfigureAwait(false);
        }
        public async System.Threading.Tasks.Task<TEntity> GetItemByPrimaryKeyAsync(long authorizationScopeResourceActionId, global::Sidvall.Data.FetchCriteria<global::Sidvall.AuthorizationManager.Data.Fields.AuthorizationScopeResourceActionField, global::Sidvall.AuthorizationManager.Data.Relations.AuthorizationScopeResourceActionRelation> criteria, string strategyContext, global::Sidvall.Data.ObjectParameterCollection objectParameters)
        {
            if (criteria == null)
                criteria = Sidvall.Data.CriteriaManager.NewFetchCriteria<global::Sidvall.AuthorizationManager.Data.Fields.AuthorizationScopeResourceActionField, global::Sidvall.AuthorizationManager.Data.Relations.AuthorizationScopeResourceActionRelation>();
            if (criteria.Filter == null)
                criteria.Filter = new global::Sidvall.Data.Filter<global::Sidvall.AuthorizationManager.Data.Fields.AuthorizationScopeResourceActionField>();
            criteria.Filter.AddFilterItem(global::Sidvall.AuthorizationManager.Data.Fields.AuthorizationScopeResourceActionField.AuthorizationScopeResourceActionId, Sidvall.Data.ComparisonOperator.Equal, authorizationScopeResourceActionId);

            return await GetItemAsync(criteria, strategyContext, objectParameters).ConfigureAwait(false);
        }

        #endregion
        #region GetItemsByPrimaryKeysAsync

        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")]
        public async System.Threading.Tasks.Task<TList> GetItemsByPrimaryKeysAsync(System.Collections.Generic.IEnumerable<long> keys)
        {
            return await GetItemsByPrimaryKeysAsync(keys, null, null, null).ConfigureAwait(false);
        }
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")]
        public async System.Threading.Tasks.Task<TList> GetItemsByPrimaryKeysAsync(System.Collections.Generic.IEnumerable<long> keys, global::Sidvall.Data.FetchListCriteria<global::Sidvall.AuthorizationManager.Data.Fields.AuthorizationScopeResourceActionField, global::Sidvall.AuthorizationManager.Data.Relations.AuthorizationScopeResourceActionRelation> criteria, string strategyContext, global::Sidvall.Data.ObjectParameterCollection objectParameters)
        {
            if ((keys == null) || (!keys.Any()))
                return (TList)this.DataPortalManager.ResourceFactory.CreateItems(global::Sidvall.AuthorizationManager.Data.Model.DomainObjects.AuthorizationScopeResourceAction);
            if (criteria == null)
                criteria = Sidvall.Data.CriteriaManager.NewFetchListCriteria<global::Sidvall.AuthorizationManager.Data.Fields.AuthorizationScopeResourceActionField, global::Sidvall.AuthorizationManager.Data.Relations.AuthorizationScopeResourceActionRelation>();
            if (criteria.Filter == null)
                criteria.Filter = new global::Sidvall.Data.Filter<global::Sidvall.AuthorizationManager.Data.Fields.AuthorizationScopeResourceActionField>();
            criteria.Filter.AddFilterItem(global::Sidvall.AuthorizationManager.Data.Fields.AuthorizationScopeResourceActionField.AuthorizationScopeResourceActionId, Sidvall.Data.ComparisonOperator.Equal, keys);

            return await GetItemsAsync(criteria, strategyContext, objectParameters).ConfigureAwait(false);
        }

        #endregion
        #region GetItemsByAuthorizationScopeResourceActionClaimsAsync

        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")]
        public async System.Threading.Tasks.Task<TList> GetItemsByAuthorizationScopeResourceActionClaimsAsync(System.Collections.Generic.IEnumerable<long> authorizationScopeResourceActionIds)
        {
            return await GetItemsByAuthorizationScopeResourceActionClaimsAsync(authorizationScopeResourceActionIds, null, null, null).ConfigureAwait(false);
        }
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")]
        public async System.Threading.Tasks.Task<TList> GetItemsByAuthorizationScopeResourceActionClaimsAsync(System.Collections.Generic.IEnumerable<long> authorizationScopeResourceActionIds, global::Sidvall.Data.FetchListCriteria<global::Sidvall.AuthorizationManager.Data.Fields.AuthorizationScopeResourceActionField, global::Sidvall.AuthorizationManager.Data.Relations.AuthorizationScopeResourceActionRelation> criteria, string strategyContext, global::Sidvall.Data.ObjectParameterCollection objectParameters)
        {
            if (criteria == null)
                criteria = Sidvall.Data.CriteriaManager.NewFetchListCriteria<global::Sidvall.AuthorizationManager.Data.Fields.AuthorizationScopeResourceActionField, global::Sidvall.AuthorizationManager.Data.Relations.AuthorizationScopeResourceActionRelation>();
            if (criteria.Filter == null)
                criteria.Filter = new global::Sidvall.Data.Filter<global::Sidvall.AuthorizationManager.Data.Fields.AuthorizationScopeResourceActionField>();
            criteria.Filter.AddFilterItem(global::Sidvall.AuthorizationManager.Data.Fields.AuthorizationScopeResourceActionField.AuthorizationScopeResourceActionId, Sidvall.Data.ComparisonOperator.Equal, authorizationScopeResourceActionIds);

            return await GetItemsAsync(criteria, strategyContext, objectParameters).ConfigureAwait(false);
        }
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")]
        public async System.Threading.Tasks.Task<TList> GetItemsByAuthorizationScopeResourceActionClaimsAsync(System.Collections.Generic.IEnumerable<global::Sidvall.AuthorizationManager.Data.IAuthorizationScopeResourceActionClaim> items)
        {
            return await GetItemsByAuthorizationScopeResourceActionClaimsAsync(items, null, null, null).ConfigureAwait(false);
        }
        partial void OnBeforeGetItemsByAuthorizationScopeResourceActionClaims(System.Collections.Generic.IEnumerable<long> ids, global::Sidvall.Data.FetchListCriteria<global::Sidvall.AuthorizationManager.Data.Fields.AuthorizationScopeResourceActionField, global::Sidvall.AuthorizationManager.Data.Relations.AuthorizationScopeResourceActionRelation> criteria, string strategyContext, global::Sidvall.Data.ObjectParameterCollection objectParameters);
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")]
        public async System.Threading.Tasks.Task<TList> GetItemsByAuthorizationScopeResourceActionClaimsAsync(System.Collections.Generic.IEnumerable<global::Sidvall.AuthorizationManager.Data.IAuthorizationScopeResourceActionClaim> items, global::Sidvall.Data.FetchListCriteria<global::Sidvall.AuthorizationManager.Data.Fields.AuthorizationScopeResourceActionField, global::Sidvall.AuthorizationManager.Data.Relations.AuthorizationScopeResourceActionRelation> criteria, string strategyContext, global::Sidvall.Data.ObjectParameterCollection objectParameters)
        {
            if (items == null)
                return (TList)this.DataPortalManager.ResourceFactory.CreateItems(global::Sidvall.AuthorizationManager.Data.Model.DomainObjects.AuthorizationScopeResourceAction);
            var ids = (from o in items
                       select o.AuthorizationScopeResourceActionId);
            if (!ids.Any())
                return (TList)this.DataPortalManager.ResourceFactory.CreateItems(global::Sidvall.AuthorizationManager.Data.Model.DomainObjects.AuthorizationScopeResourceAction);
            OnBeforeGetItemsByAuthorizationScopeResourceActionClaims(ids, criteria, strategyContext, objectParameters);

            return await GetItemsByAuthorizationScopeResourceActionClaimsAsync(ids, criteria, strategyContext, objectParameters).ConfigureAwait(false);
        }

        #endregion
        #region GetItemsByAuthorizationScopesAsync

        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")]
        public async System.Threading.Tasks.Task<TList> GetItemsByAuthorizationScopesAsync(System.Collections.Generic.IEnumerable<long> authorizationScopeIds)
        {
            return await GetItemsByAuthorizationScopesAsync(authorizationScopeIds, null, null, null).ConfigureAwait(false);
        }
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")]
        public async System.Threading.Tasks.Task<TList> GetItemsByAuthorizationScopesAsync(System.Collections.Generic.IEnumerable<long> authorizationScopeIds, global::Sidvall.Data.FetchListCriteria<global::Sidvall.AuthorizationManager.Data.Fields.AuthorizationScopeResourceActionField, global::Sidvall.AuthorizationManager.Data.Relations.AuthorizationScopeResourceActionRelation> criteria, string strategyContext, global::Sidvall.Data.ObjectParameterCollection objectParameters)
        {
            if (criteria == null)
                criteria = Sidvall.Data.CriteriaManager.NewFetchListCriteria<global::Sidvall.AuthorizationManager.Data.Fields.AuthorizationScopeResourceActionField, global::Sidvall.AuthorizationManager.Data.Relations.AuthorizationScopeResourceActionRelation>();
            if (criteria.Filter == null)
                criteria.Filter = new global::Sidvall.Data.Filter<global::Sidvall.AuthorizationManager.Data.Fields.AuthorizationScopeResourceActionField>();
            criteria.Filter.AddFilterItem(global::Sidvall.AuthorizationManager.Data.Fields.AuthorizationScopeResourceActionField.AuthorizationScopeId, Sidvall.Data.ComparisonOperator.Equal, authorizationScopeIds);

            return await GetItemsAsync(criteria, strategyContext, objectParameters).ConfigureAwait(false);
        }
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")]
        public async System.Threading.Tasks.Task<TList> GetItemsByAuthorizationScopesAsync(System.Collections.Generic.IEnumerable<global::Sidvall.AuthorizationManager.Data.IAuthorizationScope> items)
        {
            return await GetItemsByAuthorizationScopesAsync(items, null, null, null).ConfigureAwait(false);
        }
        partial void OnBeforeGetItemsByAuthorizationScopes(System.Collections.Generic.IEnumerable<long> ids, global::Sidvall.Data.FetchListCriteria<global::Sidvall.AuthorizationManager.Data.Fields.AuthorizationScopeResourceActionField, global::Sidvall.AuthorizationManager.Data.Relations.AuthorizationScopeResourceActionRelation> criteria, string strategyContext, global::Sidvall.Data.ObjectParameterCollection objectParameters);
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")]
        public async System.Threading.Tasks.Task<TList> GetItemsByAuthorizationScopesAsync(System.Collections.Generic.IEnumerable<global::Sidvall.AuthorizationManager.Data.IAuthorizationScope> items, global::Sidvall.Data.FetchListCriteria<global::Sidvall.AuthorizationManager.Data.Fields.AuthorizationScopeResourceActionField, global::Sidvall.AuthorizationManager.Data.Relations.AuthorizationScopeResourceActionRelation> criteria, string strategyContext, global::Sidvall.Data.ObjectParameterCollection objectParameters)
        {
            if (items == null)
                return (TList)this.DataPortalManager.ResourceFactory.CreateItems(global::Sidvall.AuthorizationManager.Data.Model.DomainObjects.AuthorizationScopeResourceAction);
            var ids = (from o in items
                       where (o.AuthorizationScopeId != null)
                       select o.AuthorizationScopeId.Value);
            if (!ids.Any())
                return (TList)this.DataPortalManager.ResourceFactory.CreateItems(global::Sidvall.AuthorizationManager.Data.Model.DomainObjects.AuthorizationScopeResourceAction);
            OnBeforeGetItemsByAuthorizationScopes(ids, criteria, strategyContext, objectParameters);

            return await GetItemsByAuthorizationScopesAsync(ids, criteria, strategyContext, objectParameters).ConfigureAwait(false);
        }

        #endregion
        #region GetItemsByAuthorizationScopeAsync
        
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")]
        public async System.Threading.Tasks.Task<TList> GetItemsByAuthorizationScopeAsync(long authorizationScopeId)
        {
            return await GetItemsByAuthorizationScopeAsync(authorizationScopeId, null, null, null).ConfigureAwait(false);
        }
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")]
        public async System.Threading.Tasks.Task<TList> GetItemsByAuthorizationScopeAsync(long authorizationScopeId, global::Sidvall.Data.FetchListCriteria<global::Sidvall.AuthorizationManager.Data.Fields.AuthorizationScopeResourceActionField, global::Sidvall.AuthorizationManager.Data.Relations.AuthorizationScopeResourceActionRelation> criteria, string strategyContext, global::Sidvall.Data.ObjectParameterCollection objectParameters)
        {
            if (criteria == null)
                criteria = Sidvall.Data.CriteriaManager.NewFetchListCriteria<global::Sidvall.AuthorizationManager.Data.Fields.AuthorizationScopeResourceActionField, global::Sidvall.AuthorizationManager.Data.Relations.AuthorizationScopeResourceActionRelation>();
            if (criteria.Filter == null)
                criteria.Filter = new global::Sidvall.Data.Filter<global::Sidvall.AuthorizationManager.Data.Fields.AuthorizationScopeResourceActionField>();
            criteria.Filter.AddFilterItem(global::Sidvall.AuthorizationManager.Data.Fields.AuthorizationScopeResourceActionField.AuthorizationScopeId, Sidvall.Data.ComparisonOperator.Equal, authorizationScopeId);

            return await GetItemsAsync(criteria, strategyContext, objectParameters).ConfigureAwait(false);
        }

        #endregion
        #region GetItemAsync

        public async System.Threading.Tasks.Task<TEntity> GetItemAsync(global::Sidvall.Data.FetchCriteria<global::Sidvall.AuthorizationManager.Data.Fields.AuthorizationScopeResourceActionField, global::Sidvall.AuthorizationManager.Data.Relations.AuthorizationScopeResourceActionRelation> criteria)
        {
            return await GetItemAsync(criteria, null, null).ConfigureAwait(false);
        }
        public async System.Threading.Tasks.Task<TEntity> GetItemAsync(global::Sidvall.Data.FetchCriteria<global::Sidvall.AuthorizationManager.Data.Fields.AuthorizationScopeResourceActionField, global::Sidvall.AuthorizationManager.Data.Relations.AuthorizationScopeResourceActionRelation> criteria, string strategyContext, global::Sidvall.Data.ObjectParameterCollection objectParameters)
        {
            if (criteria == null)
                throw new System.ArgumentNullException(nameof(criteria));
            var dataPortalContext = Sidvall.Business.DataPortalManager.NewContext(global::Sidvall.AuthorizationManager.Data.Model.DomainObjects.AuthorizationScopeResourceAction, Sidvall.Security.Operations.GetItems, strategyContext, criteria, (global::Sidvall.AuthorizationManager.Data.IAuthorizationScopeResourceAction)null);
            dataPortalContext.ObjectParameters.Merge(objectParameters);
            return await GetItemAsync(dataPortalContext).ConfigureAwait(false);
        }
        partial void OnBeforeGetItem(global::Sidvall.Business.DataPortalContext<global::Sidvall.AuthorizationManager.Data.IAuthorizationScopeResourceAction, global::Sidvall.Data.FetchCriteria<global::Sidvall.AuthorizationManager.Data.Fields.AuthorizationScopeResourceActionField, global::Sidvall.AuthorizationManager.Data.Relations.AuthorizationScopeResourceActionRelation>> dataPortalContext);
        partial void OnAfterGetItem(global::Sidvall.Business.DataPortalContext<global::Sidvall.AuthorizationManager.Data.IAuthorizationScopeResourceAction, global::Sidvall.Data.FetchCriteria<global::Sidvall.AuthorizationManager.Data.Fields.AuthorizationScopeResourceActionField, global::Sidvall.AuthorizationManager.Data.Relations.AuthorizationScopeResourceActionRelation>> dataPortalContext);
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")]
        public async System.Threading.Tasks.Task<TEntity> GetItemAsync(global::Sidvall.Business.DataPortalContext<global::Sidvall.AuthorizationManager.Data.IAuthorizationScopeResourceAction, global::Sidvall.Data.FetchCriteria<global::Sidvall.AuthorizationManager.Data.Fields.AuthorizationScopeResourceActionField, global::Sidvall.AuthorizationManager.Data.Relations.AuthorizationScopeResourceActionRelation>> dataPortalContext)
        {
            if (dataPortalContext == null)
                throw new System.ArgumentNullException(nameof(dataPortalContext));
            do
            {
                try
                {
                    global::Sidvall.AuthorizationManager.Model.DataPortalEventManager.DataPortalInvoke(dataPortalContext);
                    OnBeforeGetItem(dataPortalContext);
                    await dataPortalContext.DoTaskAsync().ConfigureAwait(false);
                    if (dataPortalContext.Result == Sidvall.Business.DataPortalResult.None)
                    {
                        await GetDataPortal(dataPortalContext).GetItemAsync(dataPortalContext).ConfigureAwait(false);
                    }
                    OnAfterGetItem(dataPortalContext);
                    global::Sidvall.AuthorizationManager.Model.DataPortalEventManager.DataPortalInvokeComplete(dataPortalContext);
                    await dataPortalContext.DoTaskAsync().ConfigureAwait(false);
                }
                catch (System.Exception ex)
                {
                    dataPortalContext.Exception = Sidvall.Business.DataPortalManager.GetDataPortalException(ex, dataPortalContext);
                    global::Sidvall.AuthorizationManager.Model.DataPortalEventManager.DataPortalException(dataPortalContext);
                    await dataPortalContext.DoTaskAsync(!dataPortalContext.Retry).ConfigureAwait(false);
                }
            } while (dataPortalContext.DoRetry());
            return (TEntity)dataPortalContext.ResultValueItem;
        }

        #endregion
        #region GetItemsAsync

        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")]
        public async System.Threading.Tasks.Task<TList> GetItemsAsync()
        {
            global::Sidvall.Data.FetchListCriteria<global::Sidvall.AuthorizationManager.Data.Fields.AuthorizationScopeResourceActionField, global::Sidvall.AuthorizationManager.Data.Relations.AuthorizationScopeResourceActionRelation> criteria;

            criteria = Sidvall.Data.CriteriaManager.NewFetchListCriteria<global::Sidvall.AuthorizationManager.Data.Fields.AuthorizationScopeResourceActionField, global::Sidvall.AuthorizationManager.Data.Relations.AuthorizationScopeResourceActionRelation>();

            return await GetItemsAsync(criteria, null, null).ConfigureAwait(false);
        }
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")]
        public async System.Threading.Tasks.Task<TList> GetItemsAsync(global::Sidvall.Data.FetchListCriteria<global::Sidvall.AuthorizationManager.Data.Fields.AuthorizationScopeResourceActionField, global::Sidvall.AuthorizationManager.Data.Relations.AuthorizationScopeResourceActionRelation> criteria)
        {
            return await GetItemsAsync(criteria, null, null).ConfigureAwait(false);
        }
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")]
        public async System.Threading.Tasks.Task<TList> GetItemsAsync(global::Sidvall.Data.FetchListCriteria<global::Sidvall.AuthorizationManager.Data.Fields.AuthorizationScopeResourceActionField, global::Sidvall.AuthorizationManager.Data.Relations.AuthorizationScopeResourceActionRelation> criteria, string strategyContext, global::Sidvall.Data.ObjectParameterCollection objectParameters)
        {
            global::Sidvall.Business.DataPortalContext<global::Sidvall.AuthorizationManager.Data.IAuthorizationScopeResourceAction, global::Sidvall.Data.FetchListCriteria<global::Sidvall.AuthorizationManager.Data.Fields.AuthorizationScopeResourceActionField, global::Sidvall.AuthorizationManager.Data.Relations.AuthorizationScopeResourceActionRelation>> dataPortalContext;

            if (criteria == null)
                throw new System.ArgumentNullException(nameof(criteria));
            dataPortalContext = Sidvall.Business.DataPortalManager.NewContext(global::Sidvall.AuthorizationManager.Data.Model.DomainObjects.AuthorizationScopeResourceAction, Sidvall.Security.Operations.GetItems, strategyContext, criteria, (global::Sidvall.AuthorizationManager.Data.IAuthorizationScopeResourceAction)null);
            dataPortalContext.ObjectParameters.Merge(objectParameters);

            return await GetItemsAsync(dataPortalContext).ConfigureAwait(false);
        }
        partial void OnBeforeGetItems(global::Sidvall.Business.DataPortalContext<global::Sidvall.AuthorizationManager.Data.IAuthorizationScopeResourceAction, global::Sidvall.Data.FetchListCriteria<global::Sidvall.AuthorizationManager.Data.Fields.AuthorizationScopeResourceActionField, global::Sidvall.AuthorizationManager.Data.Relations.AuthorizationScopeResourceActionRelation>> dataPortalContext);
        partial void OnAfterGetItems(global::Sidvall.Business.DataPortalContext<global::Sidvall.AuthorizationManager.Data.IAuthorizationScopeResourceAction, global::Sidvall.Data.FetchListCriteria<global::Sidvall.AuthorizationManager.Data.Fields.AuthorizationScopeResourceActionField, global::Sidvall.AuthorizationManager.Data.Relations.AuthorizationScopeResourceActionRelation>> dataPortalContext);
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")]
        public async System.Threading.Tasks.Task<TList> GetItemsAsync(global::Sidvall.Business.DataPortalContext<global::Sidvall.AuthorizationManager.Data.IAuthorizationScopeResourceAction, global::Sidvall.Data.FetchListCriteria<global::Sidvall.AuthorizationManager.Data.Fields.AuthorizationScopeResourceActionField, global::Sidvall.AuthorizationManager.Data.Relations.AuthorizationScopeResourceActionRelation>> dataPortalContext)
        {
            if (dataPortalContext == null)
                throw new System.ArgumentNullException(nameof(dataPortalContext));
            do
            {
                try
                {
                    global::Sidvall.AuthorizationManager.Model.DataPortalEventManager.DataPortalInvoke(dataPortalContext);
                    OnBeforeGetItems(dataPortalContext);
                    await dataPortalContext.DoTaskAsync().ConfigureAwait(false);
                    if (dataPortalContext.Result == Sidvall.Business.DataPortalResult.None)
                    {
                        await GetDataPortal(dataPortalContext).GetItemsAsync(dataPortalContext).ConfigureAwait(false);
                    }
                    OnAfterGetItems(dataPortalContext);
                    global::Sidvall.AuthorizationManager.Model.DataPortalEventManager.DataPortalInvokeComplete(dataPortalContext);
                    await dataPortalContext.DoTaskAsync().ConfigureAwait(false);
                }
                catch (System.Exception ex)
                {
                    dataPortalContext.Exception = Sidvall.Business.DataPortalManager.GetDataPortalException(ex, dataPortalContext);
                    global::Sidvall.AuthorizationManager.Model.DataPortalEventManager.DataPortalException(dataPortalContext);
                    await dataPortalContext.DoTaskAsync(!dataPortalContext.Retry).ConfigureAwait(false);
                }
            } while (dataPortalContext.DoRetry());
            return (TList)dataPortalContext.GetResultValueListProviderResolved();
        }

        #endregion
        #region NewItemAsync

        public async System.Threading.Tasks.Task<TEntity> NewItemAsync(global::Sidvall.Data.CreateCriteria criteria)
        {
            return await NewItemAsync(criteria, null, null).ConfigureAwait(false);
        }
        public async System.Threading.Tasks.Task<TEntity> NewItemAsync(global::Sidvall.Data.CreateCriteria criteria, string strategyContext, global::Sidvall.Data.ObjectParameterCollection objectParameters)
        {
            global::Sidvall.Business.DataPortalContext<global::Sidvall.AuthorizationManager.Data.IAuthorizationScopeResourceAction, global::Sidvall.Data.CreateCriteria> dataPortalContext;
            
            if (criteria == null)
                throw new System.ArgumentNullException(nameof(criteria));
            dataPortalContext = Sidvall.Business.DataPortalManager.NewContext(global::Sidvall.AuthorizationManager.Data.Model.DomainObjects.AuthorizationScopeResourceAction, Sidvall.Security.Operations.NewItems, strategyContext, criteria, (global::Sidvall.AuthorizationManager.Data.IAuthorizationScopeResourceAction)null);
            dataPortalContext.ObjectParameters.Merge(objectParameters);

            return await NewItemAsync(dataPortalContext).ConfigureAwait(false);
        }
        partial void OnBeforeNewItem(global::Sidvall.Business.DataPortalContext<global::Sidvall.AuthorizationManager.Data.IAuthorizationScopeResourceAction, global::Sidvall.Data.CreateCriteria> dataPortalContext);
        partial void OnAfterNewItem(global::Sidvall.Business.DataPortalContext<global::Sidvall.AuthorizationManager.Data.IAuthorizationScopeResourceAction, global::Sidvall.Data.CreateCriteria> dataPortalContext);
        public async System.Threading.Tasks.Task<TEntity> NewItemAsync(global::Sidvall.Business.DataPortalContext<global::Sidvall.AuthorizationManager.Data.IAuthorizationScopeResourceAction, global::Sidvall.Data.CreateCriteria> dataPortalContext)
        {
            if (dataPortalContext == null)
                throw new System.ArgumentNullException(nameof(dataPortalContext));
            do
            {
                try
                {
                    global::Sidvall.AuthorizationManager.Model.DataPortalEventManager.DataPortalInvoke(dataPortalContext);
                    OnBeforeNewItem(dataPortalContext);
                    await dataPortalContext.DoTaskAsync().ConfigureAwait(false);
                    if (dataPortalContext.Result == Sidvall.Business.DataPortalResult.None)
                    {
                        await GetDataPortal(dataPortalContext).NewItemAsync(dataPortalContext).ConfigureAwait(false);
                    }
                    OnAfterNewItem(dataPortalContext);
                    global::Sidvall.AuthorizationManager.Model.DataPortalEventManager.DataPortalInvokeComplete(dataPortalContext);
                    await dataPortalContext.DoTaskAsync().ConfigureAwait(false);
                }
                catch (System.Exception ex)
                {
                    dataPortalContext.Exception = Sidvall.Business.DataPortalManager.GetDataPortalException(ex, dataPortalContext);
                    global::Sidvall.AuthorizationManager.Model.DataPortalEventManager.DataPortalException(dataPortalContext);
                    await dataPortalContext.DoTaskAsync(!dataPortalContext.Retry).ConfigureAwait(false);
                }
            } while (dataPortalContext.DoRetry());
            return (TEntity)dataPortalContext.ResultValueItem;
        }

        #endregion
        #region NewItemsAsync

        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")]
        public async System.Threading.Tasks.Task<TList> NewItemsAsync()
        {
            global::Sidvall.Data.CreateCriteria criteria;

            criteria = Sidvall.Data.CriteriaManager.NewCreateCriteria();

            return await NewItemsAsync(criteria, null, null).ConfigureAwait(false);
        }
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")]
        public async System.Threading.Tasks.Task<TList> NewItemsAsync(global::Sidvall.Data.CreateCriteria criteria)
        {
            return await NewItemsAsync(criteria, null, null).ConfigureAwait(false);
        }
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")]
        public async System.Threading.Tasks.Task<TList> NewItemsAsync(global::Sidvall.Data.CreateCriteria criteria, string strategyContext, global::Sidvall.Data.ObjectParameterCollection objectParameters)
        {
            global::Sidvall.Business.DataPortalContext<global::Sidvall.AuthorizationManager.Data.IAuthorizationScopeResourceAction, global::Sidvall.Data.CreateCriteria> dataPortalContext;

            if (criteria == null)
                throw new System.ArgumentNullException(nameof(criteria));
            dataPortalContext = Sidvall.Business.DataPortalManager.NewContext(global::Sidvall.AuthorizationManager.Data.Model.DomainObjects.AuthorizationScopeResourceAction, Sidvall.Security.Operations.NewItems, strategyContext, criteria, (global::Sidvall.AuthorizationManager.Data.IAuthorizationScopeResourceAction)null);
            dataPortalContext.ObjectParameters.Merge(objectParameters);

            return await NewItemsAsync(dataPortalContext).ConfigureAwait(false);
        }
        partial void OnBeforeNewItems(global::Sidvall.Business.DataPortalContext<global::Sidvall.AuthorizationManager.Data.IAuthorizationScopeResourceAction, global::Sidvall.Data.CreateCriteria> dataPortalContext);
        partial void OnAfterNewItems(global::Sidvall.Business.DataPortalContext<global::Sidvall.AuthorizationManager.Data.IAuthorizationScopeResourceAction, global::Sidvall.Data.CreateCriteria> dataPortalContext);
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")]
        public async System.Threading.Tasks.Task<TList> NewItemsAsync(global::Sidvall.Business.DataPortalContext<global::Sidvall.AuthorizationManager.Data.IAuthorizationScopeResourceAction, global::Sidvall.Data.CreateCriteria> dataPortalContext)
        {
            if (dataPortalContext == null)
                throw new System.ArgumentNullException(nameof(dataPortalContext));
            do
            {
                try
                {
                    global::Sidvall.AuthorizationManager.Model.DataPortalEventManager.DataPortalInvoke(dataPortalContext);
                    OnBeforeNewItems(dataPortalContext);
                    await dataPortalContext.DoTaskAsync().ConfigureAwait(false);
                    if (dataPortalContext.Result == Sidvall.Business.DataPortalResult.None)
                    {
                        await GetDataPortal(dataPortalContext).NewItemsAsync(dataPortalContext).ConfigureAwait(false);
                    }
                    OnAfterNewItems(dataPortalContext);
                    global::Sidvall.AuthorizationManager.Model.DataPortalEventManager.DataPortalInvokeComplete(dataPortalContext);
                    await dataPortalContext.DoTaskAsync().ConfigureAwait(false);
                }
                catch (System.Exception ex)
                {
                    dataPortalContext.Exception = Sidvall.Business.DataPortalManager.GetDataPortalException(ex, dataPortalContext);
                    global::Sidvall.AuthorizationManager.Model.DataPortalEventManager.DataPortalException(dataPortalContext);
                    await dataPortalContext.DoTaskAsync(!dataPortalContext.Retry).ConfigureAwait(false);
                }
            } while (dataPortalContext.DoRetry());
            return (TList)dataPortalContext.GetResultValueListProviderResolved();
        }

        #endregion
        #region GetItemCountByAuthorizationScopeAsync

        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")]
        public async System.Threading.Tasks.Task<long> GetItemCountByAuthorizationScopeAsync(long authorizationScopeId)
        {
            global::Sidvall.Data.FetchCountCriteria<global::Sidvall.AuthorizationManager.Data.Fields.AuthorizationScopeResourceActionField> criteria;

            criteria = Sidvall.Data.CriteriaManager.NewFetchCountCriteria<global::Sidvall.AuthorizationManager.Data.Fields.AuthorizationScopeResourceActionField>();
            criteria.Filter = new global::Sidvall.Data.Filter<global::Sidvall.AuthorizationManager.Data.Fields.AuthorizationScopeResourceActionField>();
            criteria.Filter.AddFilterItem(global::Sidvall.AuthorizationManager.Data.Fields.AuthorizationScopeResourceActionField.AuthorizationScopeId, Sidvall.Data.ComparisonOperator.Equal, authorizationScopeId);

            return await GetItemCountAsync(criteria, null, null).ConfigureAwait(false);
        }
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")]
        public async System.Threading.Tasks.Task<long> GetItemCountByAuthorizationScopeAsync(System.Collections.Generic.IEnumerable<long> authorizationScopeIds)
        {
            global::Sidvall.Data.FetchCountCriteria<global::Sidvall.AuthorizationManager.Data.Fields.AuthorizationScopeResourceActionField> criteria;

            criteria = Sidvall.Data.CriteriaManager.NewFetchCountCriteria<global::Sidvall.AuthorizationManager.Data.Fields.AuthorizationScopeResourceActionField>();
            criteria.Filter = new global::Sidvall.Data.Filter<global::Sidvall.AuthorizationManager.Data.Fields.AuthorizationScopeResourceActionField>();
            criteria.Filter.AddFilterItem(global::Sidvall.AuthorizationManager.Data.Fields.AuthorizationScopeResourceActionField.AuthorizationScopeId, Sidvall.Data.ComparisonOperator.Equal, authorizationScopeIds);

            return await GetItemCountAsync(criteria, null, null).ConfigureAwait(false);
        }

        #endregion
        #region GetItemCountAsync

        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")]
        public async System.Threading.Tasks.Task<long> GetItemCountAsync()
        {
            global::Sidvall.Data.FetchCountCriteria<global::Sidvall.AuthorizationManager.Data.Fields.AuthorizationScopeResourceActionField> criteria;

            criteria = Sidvall.Data.CriteriaManager.NewFetchCountCriteria<global::Sidvall.AuthorizationManager.Data.Fields.AuthorizationScopeResourceActionField>();

            return await GetItemCountAsync(criteria, null, null).ConfigureAwait(false);
        }
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")]
        public async System.Threading.Tasks.Task<long> GetItemCountAsync(global::Sidvall.Data.FetchCountCriteria<global::Sidvall.AuthorizationManager.Data.Fields.AuthorizationScopeResourceActionField> criteria)
        {
            return await GetItemCountAsync(criteria, null, null).ConfigureAwait(false);
        }
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")]
        public async System.Threading.Tasks.Task<long> GetItemCountAsync(global::Sidvall.Data.FetchCountCriteria<global::Sidvall.AuthorizationManager.Data.Fields.AuthorizationScopeResourceActionField> criteria, string strategyContext, global::Sidvall.Data.ObjectParameterCollection objectParameters)
        {
            global::Sidvall.Business.DataPortalContext<long, global::Sidvall.Data.FetchCountCriteria<global::Sidvall.AuthorizationManager.Data.Fields.AuthorizationScopeResourceActionField>> dataPortalContext;

            if (criteria == null)
                throw new System.ArgumentNullException(nameof(criteria));
            dataPortalContext = Sidvall.Business.DataPortalManager.NewContext(global::Sidvall.AuthorizationManager.Data.Model.DomainObjects.AuthorizationScopeResourceAction, Sidvall.Security.Operations.GetItemsMetadata, strategyContext, criteria, 0L);
            dataPortalContext.ObjectParameters.Merge(objectParameters);

            return await GetItemCountAsync(dataPortalContext).ConfigureAwait(false);
        }
        partial void OnBeforeGetItemCount(global::Sidvall.Business.DataPortalContext<long, global::Sidvall.Data.FetchCountCriteria<global::Sidvall.AuthorizationManager.Data.Fields.AuthorizationScopeResourceActionField>> dataPortalContext);
        partial void OnAfterGetItemCount(global::Sidvall.Business.DataPortalContext<long, global::Sidvall.Data.FetchCountCriteria<global::Sidvall.AuthorizationManager.Data.Fields.AuthorizationScopeResourceActionField>> dataPortalContext);
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")]
        public async System.Threading.Tasks.Task<long> GetItemCountAsync(global::Sidvall.Business.DataPortalContext<long, global::Sidvall.Data.FetchCountCriteria<global::Sidvall.AuthorizationManager.Data.Fields.AuthorizationScopeResourceActionField>> dataPortalContext)
        {
            if (dataPortalContext == null)
                throw new System.ArgumentNullException(nameof(dataPortalContext));
            do
            {
                try
                {
                    global::Sidvall.AuthorizationManager.Model.DataPortalEventManager.DataPortalInvoke(dataPortalContext);
                    OnBeforeGetItemCount(dataPortalContext);
                    await dataPortalContext.DoTaskAsync().ConfigureAwait(false);
                    if (dataPortalContext.Result == Sidvall.Business.DataPortalResult.None)
                    {
                        await GetDataPortal(dataPortalContext).GetItemCountAsync(dataPortalContext).ConfigureAwait(false);
                    }
                    OnAfterGetItemCount(dataPortalContext);
                    global::Sidvall.AuthorizationManager.Model.DataPortalEventManager.DataPortalInvokeComplete(dataPortalContext);
                    await dataPortalContext.DoTaskAsync().ConfigureAwait(false);
                }
                catch (System.Exception ex)
                {
                    dataPortalContext.Exception = Sidvall.Business.DataPortalManager.GetDataPortalException(ex, dataPortalContext);
                    global::Sidvall.AuthorizationManager.Model.DataPortalEventManager.DataPortalException(dataPortalContext);
                    await dataPortalContext.DoTaskAsync(!dataPortalContext.Retry).ConfigureAwait(false);
                }
            } while (dataPortalContext.DoRetry());
            return dataPortalContext.ResultValueItem;
        }

        #endregion
        #region SaveItemAsync

        public async System.Threading.Tasks.Task<TEntity> SaveItemAsync(TEntity item)
        {
            return await SaveItemAsync(item, null, null, null).ConfigureAwait(false);
        }
        public async System.Threading.Tasks.Task<TEntity> SaveItemAsync(TEntity item, Sidvall.Data.SaveMode mode)
        {
            var settings = new Sidvall.Data.SaveSettings()
            {
                Mode = mode
            };
            return await SaveItemAsync(item, settings, null, null).ConfigureAwait(false);
        }
        public async System.Threading.Tasks.Task<TEntity> SaveItemAsync(TEntity item, Sidvall.Data.SaveSettings settings)
        {
            return await SaveItemAsync(item, settings, null, null).ConfigureAwait(false);
        }
        partial void OnBeforeSaveItem(global::Sidvall.Data.SaveContext<global::Sidvall.AuthorizationManager.Data.IAuthorizationScopeResourceAction> context);
        public async System.Threading.Tasks.Task<TEntity> SaveItemAsync(TEntity item, Sidvall.Data.SaveSettings settings, string strategyContext, global::Sidvall.Data.ObjectParameterCollection objectParameters)
        {
            var context = new global::Sidvall.Data.SaveContext<global::Sidvall.AuthorizationManager.Data.IAuthorizationScopeResourceAction>()
            {
                Item = item,
                Settings = settings
            };
            OnBeforeSaveItem(context);
            var dataPortalContext = Sidvall.Business.DataPortalManager.NewSaveItemContext(global::Sidvall.AuthorizationManager.Data.Model.DomainObjects.AuthorizationScopeResourceAction, strategyContext, context);
            dataPortalContext.ObjectParameters.Merge(objectParameters);
            return await SaveItemAsync(dataPortalContext).ConfigureAwait(false);
        }
        partial void OnBeforeSaveItem(global::Sidvall.Business.DataPortalContext<global::Sidvall.AuthorizationManager.Data.IAuthorizationScopeResourceAction, Sidvall.Data.SaveContext<global::Sidvall.AuthorizationManager.Data.IAuthorizationScopeResourceAction>> dataPortalContext);
        partial void OnAfterSaveItem(global::Sidvall.Business.DataPortalContext<global::Sidvall.AuthorizationManager.Data.IAuthorizationScopeResourceAction, Sidvall.Data.SaveContext<global::Sidvall.AuthorizationManager.Data.IAuthorizationScopeResourceAction>> dataPortalContext);
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")]
        public async System.Threading.Tasks.Task<TEntity> SaveItemAsync(global::Sidvall.Business.DataPortalContext<global::Sidvall.AuthorizationManager.Data.IAuthorizationScopeResourceAction, Sidvall.Data.SaveContext<global::Sidvall.AuthorizationManager.Data.IAuthorizationScopeResourceAction>> dataPortalContext)
        {
            if (dataPortalContext == null)
                throw new System.ArgumentNullException(nameof(dataPortalContext));
            do
            {
                try
                {
                    if (dataPortalContext.CopyOnSave)
                        dataPortalContext.OperationContext.Item = this.DataPortalManager.GenericEntityFacade.AuthorizationScopeResourceActionManager.Copy(dataPortalContext.OperationContext.Item, Sidvall.Data.CopySettings.Clone());
                    global::Sidvall.AuthorizationManager.Model.DataPortalEventManager.DataPortalInvoke(dataPortalContext);
                    OnBeforeSaveItem(dataPortalContext);
                    await dataPortalContext.DoTaskAsync().ConfigureAwait(false);
                    if (dataPortalContext.Result == Sidvall.Business.DataPortalResult.None)
                    {
                        await GetDataPortal(dataPortalContext).SaveItemAsync(dataPortalContext).ConfigureAwait(false);
                    }
                    OnAfterSaveItem(dataPortalContext);
                    global::Sidvall.AuthorizationManager.Model.DataPortalEventManager.DataPortalInvokeComplete(dataPortalContext);
                    await dataPortalContext.DoTaskAsync().ConfigureAwait(false);
                }
                catch (System.Exception ex)
                {
                    dataPortalContext.Exception = Sidvall.Business.DataPortalManager.GetDataPortalException(ex, dataPortalContext);
                    global::Sidvall.AuthorizationManager.Model.DataPortalEventManager.DataPortalException(dataPortalContext);
                    await dataPortalContext.DoTaskAsync(!dataPortalContext.Retry).ConfigureAwait(false);
                }
            } while (dataPortalContext.DoRetry());
            return (TEntity)dataPortalContext.ResultValueItem;
        }

        #endregion
        #region SaveItemsAsync

        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")]
        public async System.Threading.Tasks.Task<TList> SaveItemsAsync(TList items)
        {
            return await SaveItemsAsync(items, null, null, null).ConfigureAwait(false);
        }
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")]
        public async System.Threading.Tasks.Task<TList> SaveItemsAsync(TList items, Sidvall.Data.SaveMode mode)
        {
            var settings = new Sidvall.Data.SaveSettings()
            {
                Mode = mode
            };
            return await SaveItemsAsync(items, settings, null, null).ConfigureAwait(false);
        }
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")]
        public async System.Threading.Tasks.Task<TList> SaveItemsAsync(TList items, Sidvall.Data.SaveSettings settings)
        {
            return await SaveItemsAsync(items, settings, null, null).ConfigureAwait(false);
        }
        partial void OnBeforeSaveItems(global::Sidvall.Data.SaveContext<Sidvall.Data.IDataRowProvider<global::Sidvall.AuthorizationManager.Data.IAuthorizationScopeResourceAction>> context);
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")]
        public async System.Threading.Tasks.Task<TList> SaveItemsAsync(TList items, Sidvall.Data.SaveSettings settings, string strategyContext, global::Sidvall.Data.ObjectParameterCollection objectParameters)
        {
            var context = new Sidvall.Data.SaveContext<Sidvall.Data.IDataRowProvider<global::Sidvall.AuthorizationManager.Data.IAuthorizationScopeResourceAction>>()
            {
                Item = items,
                Settings = settings
            };
            OnBeforeSaveItems(context);
            var dataPortalContext = Sidvall.Business.DataPortalManager.NewSaveItemsContext(global::Sidvall.AuthorizationManager.Data.Model.DomainObjects.AuthorizationScopeResourceAction, strategyContext, context);
            dataPortalContext.ObjectParameters.Merge(objectParameters);
            return await SaveItemsAsync(dataPortalContext).ConfigureAwait(false);
        }
        partial void OnBeforeSaveItems(global::Sidvall.Business.DataPortalContext<global::Sidvall.AuthorizationManager.Data.IAuthorizationScopeResourceAction, Sidvall.Data.SaveContext<Sidvall.Data.IDataRowProvider<global::Sidvall.AuthorizationManager.Data.IAuthorizationScopeResourceAction>>> dataPortalContext);
        partial void OnAfterSaveItems(global::Sidvall.Business.DataPortalContext<global::Sidvall.AuthorizationManager.Data.IAuthorizationScopeResourceAction, Sidvall.Data.SaveContext<Sidvall.Data.IDataRowProvider<global::Sidvall.AuthorizationManager.Data.IAuthorizationScopeResourceAction>>> dataPortalContext);
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")]
        public async System.Threading.Tasks.Task<TList> SaveItemsAsync(global::Sidvall.Business.DataPortalContext<global::Sidvall.AuthorizationManager.Data.IAuthorizationScopeResourceAction, Sidvall.Data.SaveContext<Sidvall.Data.IDataRowProvider<global::Sidvall.AuthorizationManager.Data.IAuthorizationScopeResourceAction>>> dataPortalContext)
        {
            if (dataPortalContext == null)
                throw new System.ArgumentNullException(nameof(dataPortalContext));
            do
            {
                try
                {
                    if (dataPortalContext.CopyOnSave)
                        dataPortalContext.OperationContext.Item = this.DataPortalManager.GenericEntityFacade.AuthorizationScopeResourceActionManager.Copy(dataPortalContext.OperationContext.Item.DataItems, Sidvall.Data.CopySettings.Clone());
                    global::Sidvall.AuthorizationManager.Model.DataPortalEventManager.DataPortalInvoke(dataPortalContext);
                    OnBeforeSaveItems(dataPortalContext);
                    await dataPortalContext.DoTaskAsync().ConfigureAwait(false);
                    if (dataPortalContext.Result == Sidvall.Business.DataPortalResult.None)
                    {
                        await GetDataPortal(dataPortalContext).SaveItemsAsync(dataPortalContext).ConfigureAwait(false);
                    }
                    OnAfterSaveItems(dataPortalContext);
                    global::Sidvall.AuthorizationManager.Model.DataPortalEventManager.DataPortalInvokeComplete(dataPortalContext);
                    await dataPortalContext.DoTaskAsync().ConfigureAwait(false);
                }
                catch (System.Exception ex)
                {
                    dataPortalContext.Exception = Sidvall.Business.DataPortalManager.GetDataPortalException(ex, dataPortalContext);
                    global::Sidvall.AuthorizationManager.Model.DataPortalEventManager.DataPortalException(dataPortalContext);
                    await dataPortalContext.DoTaskAsync(!dataPortalContext.Retry).ConfigureAwait(false);
                }
            } while (dataPortalContext.DoRetry());
            return (TList)dataPortalContext.GetResultValueListProviderResolved();
        }

        #endregion
        #region UpdateItemAsync

        public async System.Threading.Tasks.Task<bool> UpdateItemAsync(Sidvall.Data.UpdateItemContext<global::Sidvall.AuthorizationManager.Data.Fields.AuthorizationScopeResourceActionField> context)
        {
            return await UpdateItemAsync(context, null, null).ConfigureAwait(false);
        }
        public async System.Threading.Tasks.Task<bool> UpdateItemAsync(Sidvall.Data.UpdateItemContext<global::Sidvall.AuthorizationManager.Data.Fields.AuthorizationScopeResourceActionField> context, string strategyContext, global::Sidvall.Data.ObjectParameterCollection objectParameters)
        {
            if (context == null)
                throw new System.ArgumentNullException(nameof(context));
            var dataPortalContext = Sidvall.Business.DataPortalManager.NewContext(global::Sidvall.AuthorizationManager.Data.Model.DomainObjects.AuthorizationScopeResourceAction, Sidvall.Security.Operations.UpdateItems, strategyContext, context, false);
            dataPortalContext.ObjectParameters.Merge(objectParameters);
            return await UpdateItemAsync(dataPortalContext).ConfigureAwait(false);
        }
        partial void OnBeforeUpdateItem(global::Sidvall.Business.DataPortalContext<bool, Sidvall.Data.UpdateItemContext<global::Sidvall.AuthorizationManager.Data.Fields.AuthorizationScopeResourceActionField>> dataPortalContext);
        partial void OnAfterUpdateItem(global::Sidvall.Business.DataPortalContext<bool, Sidvall.Data.UpdateItemContext<global::Sidvall.AuthorizationManager.Data.Fields.AuthorizationScopeResourceActionField>> dataPortalContext);
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")]
        public async System.Threading.Tasks.Task<bool> UpdateItemAsync(global::Sidvall.Business.DataPortalContext<bool, Sidvall.Data.UpdateItemContext<global::Sidvall.AuthorizationManager.Data.Fields.AuthorizationScopeResourceActionField>> dataPortalContext)
        {
            if (dataPortalContext == null)
                throw new System.ArgumentNullException(nameof(dataPortalContext));
            do
            {
                try
                {
                    global::Sidvall.AuthorizationManager.Model.DataPortalEventManager.DataPortalInvoke(dataPortalContext);
                    OnBeforeUpdateItem(dataPortalContext);
                    await dataPortalContext.DoTaskAsync().ConfigureAwait(false);
                    if (dataPortalContext.Result == Sidvall.Business.DataPortalResult.None)
                    {
                        await GetDataPortal(dataPortalContext).UpdateItemAsync(dataPortalContext).ConfigureAwait(false);
                    }
                    OnAfterUpdateItem(dataPortalContext);
                    global::Sidvall.AuthorizationManager.Model.DataPortalEventManager.DataPortalInvokeComplete(dataPortalContext);
                    await dataPortalContext.DoTaskAsync().ConfigureAwait(false);
                }
                catch (System.Exception ex)
                {
                    dataPortalContext.Exception = Sidvall.Business.DataPortalManager.GetDataPortalException(ex, dataPortalContext);
                    global::Sidvall.AuthorizationManager.Model.DataPortalEventManager.DataPortalException(dataPortalContext);
                    await dataPortalContext.DoTaskAsync(!dataPortalContext.Retry).ConfigureAwait(false);
                }
            } while (dataPortalContext.DoRetry());
            return dataPortalContext.ResultValueItem;
        }

        #endregion
        #region UpdateItemsAsync

        public async System.Threading.Tasks.Task<int> UpdateItemsAsync(Sidvall.Data.UpdateItemsContext<global::Sidvall.AuthorizationManager.Data.Fields.AuthorizationScopeResourceActionField> context)
        {
            return await UpdateItemsAsync(context, null, null).ConfigureAwait(false);
        }
        public async System.Threading.Tasks.Task<int> UpdateItemsAsync(Sidvall.Data.UpdateItemsContext<global::Sidvall.AuthorizationManager.Data.Fields.AuthorizationScopeResourceActionField> context, string strategyContext, global::Sidvall.Data.ObjectParameterCollection objectParameters)
        {
            if (context == null)
                throw new System.ArgumentNullException(nameof(context));
            var dataPortalContext = Sidvall.Business.DataPortalManager.NewContext(global::Sidvall.AuthorizationManager.Data.Model.DomainObjects.AuthorizationScopeResourceAction, Sidvall.Security.Operations.UpdateItems, strategyContext, context, 0);
            dataPortalContext.ObjectParameters.Merge(objectParameters);
            return await UpdateItemsAsync(dataPortalContext).ConfigureAwait(false);
        }
        partial void OnBeforeUpdateItems(global::Sidvall.Business.DataPortalContext<int, Sidvall.Data.UpdateItemsContext<global::Sidvall.AuthorizationManager.Data.Fields.AuthorizationScopeResourceActionField>> dataPortalContext);
        partial void OnAfterUpdateItems(global::Sidvall.Business.DataPortalContext<int, Sidvall.Data.UpdateItemsContext<global::Sidvall.AuthorizationManager.Data.Fields.AuthorizationScopeResourceActionField>> dataPortalContext);
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")]
        public async System.Threading.Tasks.Task<int> UpdateItemsAsync(global::Sidvall.Business.DataPortalContext<int, Sidvall.Data.UpdateItemsContext<global::Sidvall.AuthorizationManager.Data.Fields.AuthorizationScopeResourceActionField>> dataPortalContext)
        {
            if (dataPortalContext == null)
                throw new System.ArgumentNullException(nameof(dataPortalContext));
            do
            {
                try
                {
                    global::Sidvall.AuthorizationManager.Model.DataPortalEventManager.DataPortalInvoke(dataPortalContext);
                    OnBeforeUpdateItems(dataPortalContext);
                    await dataPortalContext.DoTaskAsync().ConfigureAwait(false);
                    if (dataPortalContext.Result == Sidvall.Business.DataPortalResult.None)
                    {
                        await GetDataPortal(dataPortalContext).UpdateItemsAsync(dataPortalContext).ConfigureAwait(false);
                    }
                    OnAfterUpdateItems(dataPortalContext);
                    global::Sidvall.AuthorizationManager.Model.DataPortalEventManager.DataPortalInvokeComplete(dataPortalContext);
                    await dataPortalContext.DoTaskAsync().ConfigureAwait(false);
                }
                catch (System.Exception ex)
                {
                    dataPortalContext.Exception = Sidvall.Business.DataPortalManager.GetDataPortalException(ex, dataPortalContext);
                    global::Sidvall.AuthorizationManager.Model.DataPortalEventManager.DataPortalException(dataPortalContext);
                    await dataPortalContext.DoTaskAsync(!dataPortalContext.Retry).ConfigureAwait(false);
                }
            } while (dataPortalContext.DoRetry());
            return dataPortalContext.ResultValueItem;
        }

        #endregion
        #region ExecuteAsync

        public async System.Threading.Tasks.Task<global::Sidvall.Data.CommandCriteria> ExecuteAsync(string commandId, Sidvall.Data.ParameterCollection parameters)
        {
            global::Sidvall.Data.CommandCriteria criteria;

            criteria = Sidvall.Data.CriteriaManager.NewCommandCriteria(commandId, parameters);

            return await ExecuteAsync(criteria, null, null).ConfigureAwait(false);
        }
        public async System.Threading.Tasks.Task<global::Sidvall.Data.CommandCriteria> ExecuteAsync(global::Sidvall.Data.CommandCriteria criteria)
        {
            return await ExecuteAsync(criteria, null, null).ConfigureAwait(false);
        }
        public async System.Threading.Tasks.Task<global::Sidvall.Data.CommandCriteria> ExecuteAsync(global::Sidvall.Data.CommandCriteria criteria, string strategyContext, global::Sidvall.Data.ObjectParameterCollection objectParameters)
        {
            global::Sidvall.Business.DataPortalContext<global::Sidvall.Data.CommandCriteria, global::Sidvall.Data.CommandCriteria> dataPortalContext;

            if (criteria == null)
                throw new System.ArgumentNullException(nameof(criteria));
            dataPortalContext = Sidvall.Business.DataPortalManager.NewContext(global::Sidvall.AuthorizationManager.Data.Model.DomainObjects.AuthorizationScopeResourceAction, Sidvall.Security.Operations.Execute, strategyContext, criteria);
            dataPortalContext.ObjectParameters.Merge(objectParameters);

            return await ExecuteAsync(dataPortalContext).ConfigureAwait(false);
        }
        partial void OnBeforeExecute(global::Sidvall.Business.DataPortalContext<global::Sidvall.Data.CommandCriteria, global::Sidvall.Data.CommandCriteria> dataPortalContext);
        partial void OnAfterExecute(global::Sidvall.Business.DataPortalContext<global::Sidvall.Data.CommandCriteria, global::Sidvall.Data.CommandCriteria> dataPortalContext);
        public async System.Threading.Tasks.Task<global::Sidvall.Data.CommandCriteria> ExecuteAsync(global::Sidvall.Business.DataPortalContext<global::Sidvall.Data.CommandCriteria, global::Sidvall.Data.CommandCriteria> dataPortalContext)
        {
            if (dataPortalContext == null)
                throw new System.ArgumentNullException(nameof(dataPortalContext));
            do
            {
                try
                {
                    global::Sidvall.AuthorizationManager.Model.DataPortalEventManager.DataPortalInvoke(dataPortalContext);
                    OnBeforeExecute(dataPortalContext);
                    await dataPortalContext.DoTaskAsync().ConfigureAwait(false);
                    if (dataPortalContext.Result == Sidvall.Business.DataPortalResult.None)
                    {
                        await GetDataPortal(dataPortalContext).ExecuteAsync(dataPortalContext).ConfigureAwait(false);
                    }
                    OnAfterExecute(dataPortalContext);
                    global::Sidvall.AuthorizationManager.Model.DataPortalEventManager.DataPortalInvokeComplete(dataPortalContext);
                    await dataPortalContext.DoTaskAsync().ConfigureAwait(false);
                }
                catch (System.Exception ex)
                {
                    dataPortalContext.Exception = Sidvall.Business.DataPortalManager.GetDataPortalException(ex, dataPortalContext);
                    global::Sidvall.AuthorizationManager.Model.DataPortalEventManager.DataPortalException(dataPortalContext);
                    await dataPortalContext.DoTaskAsync(!dataPortalContext.Retry).ConfigureAwait(false);
                }
            } while (dataPortalContext.DoRetry());
            return dataPortalContext.ResultValueItem;
        }

        #endregion
        #region LoadAuthorizationScopeResourceActionClaimsAsync

        partial void OnBeforeLoadAuthorizationScopeResourceActionClaimsAsync(ref System.Threading.Tasks.Task<Sidvall.Data.IDataRowProvider<global::Sidvall.AuthorizationManager.Data.IAuthorizationScopeResourceActionClaim>> task, global::Sidvall.Data.FetchListCriteria<global::Sidvall.AuthorizationManager.Data.Fields.AuthorizationScopeResourceActionClaimField, global::Sidvall.AuthorizationManager.Data.Relations.AuthorizationScopeResourceActionClaimRelation> criteria, string strategyContext, global::Sidvall.Data.ObjectParameterCollection objectParameters);
        public async System.Threading.Tasks.Task LoadAuthorizationScopeResourceActionClaimsAsync(global::Sidvall.AuthorizationManager.Data.IAuthorizationScopeResourceAction item, bool refresh, bool raisePropertyChanged, global::Sidvall.Data.FetchListCriteria<global::Sidvall.AuthorizationManager.Data.Fields.AuthorizationScopeResourceActionClaimField, global::Sidvall.AuthorizationManager.Data.Relations.AuthorizationScopeResourceActionClaimRelation> criteria, string strategyContext, global::Sidvall.Data.ObjectParameterCollection objectParameters)
        {
            Sidvall.Data.IDataRowProvider<global::Sidvall.AuthorizationManager.Data.IAuthorizationScopeResourceActionClaim> bo;
            System.Threading.Tasks.Task<Sidvall.Data.IDataRowProvider<global::Sidvall.AuthorizationManager.Data.IAuthorizationScopeResourceActionClaim>> task;

            if (item.DataRowStateIsNew)
            {
                if ((item.AuthorizationScopeResourceActionClaims == null) || (refresh))
                {
                    bo = (Sidvall.Data.IDataRowProvider<global::Sidvall.AuthorizationManager.Data.IAuthorizationScopeResourceActionClaim>)this.DataPortalManager.ResourceFactory.CreateItems(global::Sidvall.AuthorizationManager.Data.Model.DomainObjects.AuthorizationScopeResourceActionClaim);
                    item.SetAuthorizationScopeResourceActionClaims(bo);
                    Sidvall.Data.EntityManager.OnPropertyChanged(item, "AuthorizationScopeResourceActionClaims", raisePropertyChanged, false);
                }
            }
            else
            {
                if ((item.AuthorizationScopeResourceActionClaims == null) || (refresh))
                {
                    if (item.AuthorizationScopeResourceActionId != null)
                    {
                        task = null;
                        OnBeforeLoadAuthorizationScopeResourceActionClaimsAsync(ref task, criteria, strategyContext, objectParameters);
                        if (task != null)
                            bo = await task.ConfigureAwait(false);
                        else
                            bo = await this.DataPortalManager.GenericDataPortal.AuthorizationScopeResourceActionClaimManager.GetItemsByAuthorizationScopeResourceActionAsync(item.AuthorizationScopeResourceActionId.Value, criteria, strategyContext, objectParameters).ConfigureAwait(false);
                        item.SetAuthorizationScopeResourceActionClaims(bo);
                        Sidvall.Data.EntityManager.OnPropertyChanged(item, "AuthorizationScopeResourceActionClaims", raisePropertyChanged, false);
                    }
                }
            }
        }
        partial void OnBeforeLoadAuthorizationScopeResourceActionClaims(System.Collections.Generic.IEnumerable<long> ids, global::Sidvall.Data.FetchListCriteria<global::Sidvall.AuthorizationManager.Data.Fields.AuthorizationScopeResourceActionClaimField, global::Sidvall.AuthorizationManager.Data.Relations.AuthorizationScopeResourceActionClaimRelation> criteria, string strategyContext, global::Sidvall.Data.ObjectParameterCollection objectParameters);
        public async System.Threading.Tasks.Task LoadAuthorizationScopeResourceActionClaimsAsync(System.Collections.Generic.IEnumerable<global::Sidvall.AuthorizationManager.Data.IAuthorizationScopeResourceAction> items, bool refresh, bool raisePropertyChanged, global::Sidvall.Data.FetchListCriteria<global::Sidvall.AuthorizationManager.Data.Fields.AuthorizationScopeResourceActionClaimField, global::Sidvall.AuthorizationManager.Data.Relations.AuthorizationScopeResourceActionClaimRelation> criteria, string strategyContext, global::Sidvall.Data.ObjectParameterCollection objectParameters)
        {
            System.Collections.ObjectModel.Collection<global::Sidvall.AuthorizationManager.Data.IAuthorizationScopeResourceActionClaim> relatedList;

            if (items == null)
                return;

            var selectedItems = GetItemsWithUnloadedRelation(items, global::Sidvall.AuthorizationManager.Data.Relations.AuthorizationScopeResourceActionRelation.AuthorizationScopeResourceActionClaims, refresh, criteria);
            var relatedItems = await this.DataPortalManager.GenericDataPortal.AuthorizationScopeResourceActionClaimManager.GetItemsByAuthorizationScopeResourceActionsAsync(selectedItems, criteria, strategyContext, objectParameters).ConfigureAwait(false);
            var relatedListIndex = relatedItems.DataItems.ToDictionaryCollection(o => o.AuthorizationScopeResourceActionId);

            foreach (var selectedItem in selectedItems)
            {
                if ((relatedListIndex.TryGetValue(selectedItem.AuthorizationScopeResourceActionId.Value, out relatedList)) && (relatedList != null))
                    selectedItem.SetAuthorizationScopeResourceActionClaims(this.DataPortalManager.GenericEntityFacade.AuthorizationScopeResourceActionClaimManager.Copy(relatedList, new Sidvall.Data.CopySettings(Sidvall.Business.FieldCopyOptions.All, Sidvall.Data.DataRowContextOption.State, null)));
                else
                    selectedItem.SetAuthorizationScopeResourceActionClaims((Sidvall.Data.IDataRowProvider<global::Sidvall.AuthorizationManager.Data.IAuthorizationScopeResourceActionClaim>)this.DataPortalManager.ResourceFactory.CreateItems(global::Sidvall.AuthorizationManager.Data.Model.DomainObjects.AuthorizationScopeResourceActionClaim));
                Sidvall.Data.EntityManager.OnPropertyChanged(selectedItem, "AuthorizationScopeResourceActionClaims", raisePropertyChanged, false);
            }
        }

        #endregion
        #region LoadAuthorizationScopesAsync

        partial void OnBeforeLoadAuthorizationScopeAsync(ref System.Threading.Tasks.Task<global::Sidvall.AuthorizationManager.Data.IAuthorizationScope> task, global::Sidvall.Data.FetchCriteria<global::Sidvall.AuthorizationManager.Data.Fields.AuthorizationScopeField, global::Sidvall.AuthorizationManager.Data.Relations.AuthorizationScopeRelation> criteria, string strategyContext, global::Sidvall.Data.ObjectParameterCollection objectParameters);
        public async System.Threading.Tasks.Task LoadAuthorizationScopeAsync(global::Sidvall.AuthorizationManager.Data.IAuthorizationScopeResourceAction item, bool refresh, bool raisePropertyChanged, global::Sidvall.Data.FetchCriteria<global::Sidvall.AuthorizationManager.Data.Fields.AuthorizationScopeField, global::Sidvall.AuthorizationManager.Data.Relations.AuthorizationScopeRelation> criteria, string strategyContext, global::Sidvall.Data.ObjectParameterCollection objectParameters)
        {
            global::Sidvall.AuthorizationManager.Data.IAuthorizationScope bo;
            System.Threading.Tasks.Task<global::Sidvall.AuthorizationManager.Data.IAuthorizationScope> task;

            if (item.DataRowStateIsNew)
            {
                if ((item.AuthorizationScope == null) || (refresh))
                {
                    task = null;
                    OnBeforeLoadAuthorizationScopeAsync(ref task, criteria, strategyContext, objectParameters);
                    if (task != null)
                        bo = await task.ConfigureAwait(false);
                    else
                        bo = await this.DataPortalManager.GenericDataPortal.AuthorizationScopeManager.GetItemByPrimaryKeyAsync(item.AuthorizationScopeId, criteria, strategyContext, objectParameters).ConfigureAwait(false);
                    item.AuthorizationScope = bo;
                    Sidvall.Data.EntityManager.OnPropertyChanged(item, "AuthorizationScope", raisePropertyChanged, false);
                }
            }
            else
            {
                if ((item.AuthorizationScope == null) || (refresh))
                {
                    task = null;
                    OnBeforeLoadAuthorizationScopeAsync(ref task, criteria, strategyContext, objectParameters);
                    if (task != null)
                        bo = await task.ConfigureAwait(false);
                    else
                        bo = await this.DataPortalManager.GenericDataPortal.AuthorizationScopeManager.GetItemByPrimaryKeyAsync(item.AuthorizationScopeId, criteria, strategyContext, objectParameters).ConfigureAwait(false);
                    item.AuthorizationScope = bo;
                    Sidvall.Data.EntityManager.OnPropertyChanged(item, "AuthorizationScope", raisePropertyChanged, false);
                }
            }
        }
        partial void OnBeforeLoadAuthorizationScope(System.Collections.Generic.IEnumerable<long> ids, global::Sidvall.Data.FetchListCriteria<global::Sidvall.AuthorizationManager.Data.Fields.AuthorizationScopeField, global::Sidvall.AuthorizationManager.Data.Relations.AuthorizationScopeRelation> criteria, string strategyContext, global::Sidvall.Data.ObjectParameterCollection objectParameters);
        public async System.Threading.Tasks.Task LoadAuthorizationScopesAsync(System.Collections.Generic.IEnumerable<global::Sidvall.AuthorizationManager.Data.IAuthorizationScopeResourceAction> items, bool refresh, bool raisePropertyChanged, global::Sidvall.Data.FetchListCriteria<global::Sidvall.AuthorizationManager.Data.Fields.AuthorizationScopeField, global::Sidvall.AuthorizationManager.Data.Relations.AuthorizationScopeRelation> criteria, string strategyContext, global::Sidvall.Data.ObjectParameterCollection objectParameters)
        {
            global::Sidvall.AuthorizationManager.Data.IAuthorizationScope parent;

            if (items == null)
                return;

            var selectedItems = GetItemsWithUnloadedRelation(items, global::Sidvall.AuthorizationManager.Data.Relations.AuthorizationScopeResourceActionRelation.AuthorizationScope, refresh, criteria);
            var relatedItems = await this.DataPortalManager.GenericDataPortal.AuthorizationScopeManager.GetItemsByAuthorizationScopeResourceActionsAsync(selectedItems, criteria, strategyContext, objectParameters).ConfigureAwait(false);
            var relatedListIndex = relatedItems.DataItems.ToDictionary(o => o.AuthorizationScopeId.Value, true);

            foreach (var selectedItem in selectedItems)
            {
                if (relatedListIndex.TryGetValue(selectedItem.AuthorizationScopeId, out parent))
                {
                    if (parent != null)
                        selectedItem.AuthorizationScope = this.DataPortalManager.GenericEntityFacade.AuthorizationScopeManager.Copy(parent, new Sidvall.Data.CopySettings(Sidvall.Business.FieldCopyOptions.All, Sidvall.Data.DataRowContextOption.State, null));
                    else
                        selectedItem.AuthorizationScope = null;
                    Sidvall.Data.EntityManager.OnPropertyChanged(selectedItem, "AuthorizationScope", raisePropertyChanged, false);
                }
            }
        }

        #endregion
        #region GetDataPortal

        protected global::Sidvall.Business.IDataPortal GetDataPortal(global::Sidvall.Business.IDataPortalContext dataPortalContext)
        {
            if (this.AlwaysUseLocalDataPortal)
                return this.DataPortalManager.LocalDataPortal;
            if (global::Sidvall.AuthorizationManager.SystemContext.Current.DataPortalStrategy.RunLocal(dataPortalContext))
                return this.DataPortalManager.LocalDataPortal;
            else
                return this.DataPortalManager.RemoteDataPortal;
        }

        #endregion

        #endregion
        #region Private Members

        private global::Sidvall.AuthorizationManager.Model.IDataPortalManager DataPortalManager { get; set; }
        private bool AlwaysUseLocalDataPortal { get; set; }
        #region GetItemsWithUnloadedRelation

        static partial void OnAfterGetItemsWithUnloadedRelation(ref System.Collections.Generic.IEnumerable<global::Sidvall.AuthorizationManager.Data.IAuthorizationScopeResourceAction> selectedItems, global::Sidvall.AuthorizationManager.Data.Relations.AuthorizationScopeResourceActionRelation relation, Sidvall.Data.ICriteria criteria);
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA1801:ReviewUnusedParameters", MessageId = "criteria"), System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Maintainability", "CA1502:AvoidExcessiveComplexity")]
        internal static System.Collections.Generic.IEnumerable<global::Sidvall.AuthorizationManager.Data.IAuthorizationScopeResourceAction> GetItemsWithUnloadedRelation(System.Collections.Generic.IEnumerable<global::Sidvall.AuthorizationManager.Data.IAuthorizationScopeResourceAction> items, global::Sidvall.AuthorizationManager.Data.Relations.AuthorizationScopeResourceActionRelation relation, bool refresh, Sidvall.Data.ICriteria criteria)
        {
            System.Collections.Generic.IEnumerable<global::Sidvall.AuthorizationManager.Data.IAuthorizationScopeResourceAction> result;

            if (items == null)
                return null;
            switch (relation)
            {
                case global::Sidvall.AuthorizationManager.Data.Relations.AuthorizationScopeResourceActionRelation.AuthorizationScopeResourceActionClaims:
                    result = from o in items
                             where (o.AuthorizationScopeResourceActionId != null) && ((refresh) || (o.AuthorizationScopeResourceActionClaims == null))
                             select o;
                    OnAfterGetItemsWithUnloadedRelation(ref result, relation, criteria);
                    return result;
                case global::Sidvall.AuthorizationManager.Data.Relations.AuthorizationScopeResourceActionRelation.AuthorizationScope:
                    result = from o in items
                             where ((refresh) || (o.AuthorizationScope == null))
                             select o;
                    OnAfterGetItemsWithUnloadedRelation(ref result, relation, criteria);
                    return result;
                default:
                    return null;
            }
        }

        #endregion

        #endregion
        #region Constructors

        public AuthorizationScopeResourceActionManager(global::Sidvall.AuthorizationManager.Model.IDataPortalManager dataPortalManager, bool alwaysUseLocalDataPortal)
        {
            this.DataPortalManager = dataPortalManager;
            this.AlwaysUseLocalDataPortal = alwaysUseLocalDataPortal;
        }

        #endregion
    }
}